package cn.otrue.patienthealthmanager.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.Gravity;
import android.widget.TextView;
import cn.otrue.patienthealthmanager.R;

public class MyTextView extends TextView {

	private Context mContext;
	private boolean isSelected;

	public MyTextView(Context context) {
		super(context);
		initView(context);
	}

	public MyTextView(Context context, AttributeSet attrs) {
		super(context, attrs);
		initView(context);
	}

	public MyTextView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		initView(context);
	}

	@SuppressWarnings("deprecation")
	private void initView(Context context) {
		mContext = context;
		if (isSelected)
			setBackgroundDrawable(context.getResources().getDrawable(
					R.drawable.body_state_selected_bg));
		else
			setBackgroundDrawable(context.getResources().getDrawable(
					R.drawable.selector_other_selector));
		setGravity(Gravity.CENTER);
		// setClickable(true);把这个开关打开后，整体的TextView就不会响应GridView的OnitemClickListener事件了
	}

	public boolean isChosed() {
		return isSelected;
	}

	@SuppressWarnings("deprecation")
	@Override
	public void setSelected(boolean selected) {
		if (selected) {
			setBackgroundDrawable(mContext.getResources().getDrawable(
					R.drawable.body_state_selected_bg));
			isSelected = true;

		} else {
			setBackgroundDrawable(mContext.getResources().getDrawable(
					R.drawable.selector_other_selector));
			isSelected = false;
		}
	}

}